package com.cloud.shopping.goods.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cloud.shopping.goods.mapper.BrandMapper;
import com.cloud.shopping.goods.model.Brand;
import com.cloud.shopping.goods.service.BrandService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author John.zhang
 * @version Id: BrandServiceImpl, v 1.0 2020/12/25 14:15 ZhiYong Exp $
 */

@Service
public class BrandServiceImpl extends ServiceImpl<BrandMapper, Brand> implements BrandService {


    @Resource
    private BrandMapper brandMapper;

    @Override
    public List<Brand> queryList(Brand brand) {
        //条件包装对象
        QueryWrapper<Brand> queryWrapper = new QueryWrapper<>();
        //根据name查询品牌
        queryWrapper.like("name", brand.getName());
        //根据initial查询
        queryWrapper.eq("initial", brand.getInitial());

        return brandMapper.selectList(queryWrapper);
    }

    @Override
    public Page<Brand> queryPageList(Brand brand, Long currentPage, Long size) {
        //条件包装对象
        QueryWrapper<Brand> queryWrapper = new QueryWrapper<>();
        //根据name查询品牌
        queryWrapper.like("name", brand.getName());
        return brandMapper.selectPage(new Page<>(currentPage, size), queryWrapper);
    }
}
